package com.java.thread.exer2;

/**
 * @author luzhikun
 * @date &{DATE}-17:22
 */

/**
 * 用继承Thread类的方式实现三个窗口进行买票
 * <p>
 * 存在线程安全问题，待解决
 */
public class WindowsTest {
    public static void main(String[] args) {
        Windou windou = new Windou("窗口一");
        Windou windou1 = new Windou("窗口二");
        Windou windou2 = new Windou("窗口三");

        windou.start();
        windou1.start();
        windou2.start();
    }
}

class Windou extends Thread {
    private static int ticket = 100;

    public Windou(String name) {
        super(name);
    }

    public void run() {
        while (true) {
            if (ticket > 0) {
                System.out.println(getName() + " 恭喜您买到了票，您的票号为：" + ticket);
                ticket--;
            } else {
                System.out.println("对不起，没票了");
                break;
            }
//            try {
//                Thread.sleep(100);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
        }
    }
}